<template>
  <div>
    <div class="banner" @click="handleBannerClick">
      <img :src="bannerImg" alt="" class="banner-img">
      <div class="banner-info">
        <div class="banner-title">
          {{ sightName }}
        </div>
        <div class="banner-number">
          <span class="iconfont icon">&#xe631;</span>
          {{ bannerImgs.length }}
        </div>
      </div>
    </div>
    <fade-animation>
      <gallary v-show="showGallary"
               :imgs="bannerImgs" @close="handleGallaryClose"
      >
      </gallary>
    </fade-animation>
  </div>
</template>

<script>
import Gallary from '../../../common/gallary/Gallary'
import FadeAnimation from '../../../common/fade/fadeAnimation'
import {ref} from "vue";

export default {
  name: 'DetailBanner',
  components: {
    Gallary,
    FadeAnimation
  },
  props: {
    sightName: String,
    bannerImg: String,
    bannerImgs: Array
  },
  setup() {
    const showGallary = ref(false)

    function handleBannerClick() {
      showGallary.value = true
    }

    function handleGallaryClose() {
      showGallary.value = false
      toTop()
    }

    function toTop() {
      let top = document.documentElement.scrollTop || document.body.scrollTop
      const timeTop = setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -= 50
        if (top <= 0) {
          clearInterval(timeTop)
        }
      }, 1)
    }

    return {showGallary, handleBannerClick, handleGallaryClose}
  }
}
</script>

<style lang="stylus" scoped>
.banner
  position relative
  overflow hidden
  height 0
  padding-bottom 50%

  .banner-img
    width 100%

  .banner-info
    background-image linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8))
    position absolute
    left 0
    right 0
    bottom 0
    line-height .6rem
    display flex
    color #fff

    .banner-title
      flex 1
      font-size .32rem
      padding 0 .2rem

    .banner-number
      padding 0 .4rem
      line-height .45rem
      height .45rem
      border-radius .2rem
      background rgba(0, 0, 0, .8)
      font-size .24rem
      margin-top .1rem
      margin-bottom .1rem

      .icon
        font-size .2rem
</style>
